package com.offcn.mq.listenner;

import com.offcn.mq.config.MqName;
import com.offcn.mq.utils.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author ld
 * @date 2021/9/18 16:16
 *
 */
@Component
public class SmsListener {
    @Autowired
    public SmsUtil smsUtil;

    /**
     * 监听器,用于发送短信
     * @param message
     */
    @RabbitListener(queues = MqName.SIMPLEQUEUE)
    public void getMessage(Map<String,String> message) {
        String code = message.get("code");
        String phoneNum = message.get("phoneNum");
        try {
            smsUtil.sendMsg(phoneNum, code);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
